#ifndef KEYLOCK_H
#define KEYLOCK_H

#include <windows.h>
#include <WindowsX.h>
#include <stdio.h>
#include <Dbt.h>
#include <Wtsapi32.h>
#include <uxtheme.h>
#include <wingdi.h>
#include <list>
#include <map>

class KeyLock;

#include "Settings.h"
#include "resource.h"
#include "CassiopeiaLibrary.h"

using namespace std;

class KeyLock : public CassiopeiaComponent
{
public:
	KeyLock(HINSTANCE hInstance);
	~KeyLock();
	CCState Activate();
	CCState Deactivate();

	void SetPrimaryDevice();
	void SetSecondaryDevice();
	void ClearPrimaryDevice();
	void ClearSecondaryDevice();
	bool GetLockAtUnplug();
	void SetLockAtUnplug(bool value);
	void Lock();
private:
	void Unlock();
	bool IsKeyPluggedIn();
	void RefreshKeyVolumeLetter();
	
	Window* keyLockHiddenWindow;
	Window* lockWindow;
	RegisterDriveWindow* registerDriveWindow;

	//list<Window*> lockWindows;

	HINSTANCE hInstance;

	TCHAR primaryKeyVolumeLetter;
	TCHAR secondaryKeyVolumeLetter;
	DWORD primaryKeySerial;
	DWORD secondaryKeySerial;
	
	bool wasLocked;
	bool locked;
	bool lockAtUnplug;
	bool unauthorizedLoginOccured;


	static map<HWND, KeyLock*> instances;
	
	static LRESULT CALLBACK HiddenWindowWndProc(LPVOID sender, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
	static LRESULT CALLBACK LockWindowWndProc(LPVOID sender, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
	static void DrivePluggedIn(RegisterDriveWindow* sender, TCHAR driveLetter, DWORD driveSerial, LPVOID parent, LPVOID tag);
	//static BOOL CALLBACK EnumDisplayMonitorsProc(HMONITOR hMonitor, HDC hdc, LPRECT lpRect, LPARAM lParam);
};

#endif
